package com.example.presentshopping.config.base

import android.R
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import com.example.presentshopping.utils.tool.unit.DimenUtil

abstract class BaseFragmentDialog : DialogFragment() {
    //调整窗口样式
    override fun onStart() {
        super.onStart()
        // 弹框添加。
        val dialog = dialog
        if (dialog != null && activity != null) {
            //设置窗口的背景
            dialog.window!!.setBackgroundDrawableResource(R.color.transparent)
            val lp = dialog.window!!.attributes
            lp.dimAmount = 0.8f //设置窗口后面的暗度
            // lp.alpha = 0.8f;//设置dialog窗口的透明度
            //设置dialog窗口的宽
            lp.width = ((DimenUtil.getScreenWidth() * 0.95f).toInt())
            lp.height = ((DimenUtil.getScreenHeight()*0.55).toInt())//设置dialog窗口的高
            dialog.window!!.attributes = lp
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        dialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
        dialog!!.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val view = inflater.inflate(layoutId, container, false)
        // 初始化视图
        initView(view, savedInstanceState)
        return view
    }

    /**
     * 初始化视图
     */
    protected abstract fun initView(view: View?, savedInstanceState: Bundle?)
    override fun onDestroyView() {
        super.onDestroyView()
    }

    abstract val layoutId: Int


}